package com.sneakxy.cloudbase.platform.service;

import java.util.List;
import java.util.Map;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.sneakxy.cloudbase.platform.bean.dto.DictDTO;
import com.sneakxy.cloudbase.platform.bean.dto.DictParams;
import com.sneakxy.cloudbase.platform.bean.dto.InitDTO;
import com.sneakxy.cloudbase.platform.bean.dto.LauncherDTO;
import com.sneakxy.cloudbase.platform.utils.web.Response;

@FeignClient(name="security-producer", fallbackFactory = IndexClientFallbackFactory.class)
public interface IndexClient {

	@GetMapping("/security/api/index/init")
	public Response<InitDTO> init(
			@RequestParam(name="menuType", required=false) String menuType);
	
	@GetMapping("/security/api/index/settings")
	public Response<Map<String, String>> settings();
	
	@GetMapping("/security/api/index/setting")
	public Response<String> setting(
			@RequestParam(name="key")
			String key,
			@RequestParam(name="value", required=false)
			String value);
	
	@GetMapping("/security/api/index/singlesetting")
	public Response<String> setting(
				@RequestParam(name="key")
				String key);
	
	@PostMapping("/security/api/login")
	public Response<String> login(
			@RequestParam(name="username")
			String username,
			@RequestParam(name="password")
			String password,
			@RequestParam(name="host", required = false)
			String host,
			@RequestParam(name="rememberMe", required=false, defaultValue = "1")
			boolean rememberMe);
	
	@PostMapping("/security/api/mobile")
	public Response<String> mobile(
			@RequestParam(name="mobile")
			String username,
			@RequestParam(name="code")
			String password,
			@RequestParam(name="host", required = false)
			String host,
			@RequestParam(name="rememberMe", required=false, defaultValue = "1")
			boolean rememberMe);
	
	@GetMapping("/security/api/logout")
	public Response<String> logout();
	
	@PostMapping("/security/api/perms")
	public Response<Map<String, Boolean>> perms(@SpringQueryMap Map<String, String> perms);
	
	@PostMapping("/security/api/roles")
	public Response<Map<String, Boolean>> roles(@SpringQueryMap Map<String, String> roles);
	
	@PostMapping("/security/api/dict")
	public Response<DictDTO> dict(
			@RequestParam(name="values")
			String[] values, 
			@RequestParam(name="children", required=false, defaultValue="0")
			boolean children);
	
	@PostMapping("/security/api/dicts")
	public Response<Map<String, DictDTO>> dicts(@RequestBody DictParams params);
	
	@PostMapping("/security/api/index/password")
	public Response<String> password(
			@RequestParam(name="oldPassword")
			String oldPassword,
			@RequestParam(name="password")
			String password);
	
	@PostMapping("/security/api/index/launchers")
	public Response<List<LauncherDTO>> launchers();
	
	@PostMapping("/security/api/index/launcher")
	public Response<String> launcher(
			@RequestParam(name="lid")
			String lid,
			@RequestParam(name="enable")
			boolean enable);
	
}
